import 'package:OASys/api/MeetingApi.dart';
import 'package:OASys/components/FormComponents.dart';
import 'package:OASys/components/scaffoldItem.dart';
import 'package:OASys/entity/MeetingInfoVo.dart';
import 'package:OASys/entity/UserVo.dart';
import 'package:OASys/utils/strUtils.dart';
import 'package:flutter/material.dart';

class MeetingDetail extends StatelessWidget {
  final Map arguments;
  MeetingDetail({Key key, this.arguments});

  @override
  Widget build(BuildContext context) {
    return ScaffoldItem("会议详情", MyMeetingDetail(id: arguments["id"]));
  }
}

class MyMeetingDetail extends StatefulWidget {
  final int id;
  MyMeetingDetail({Key key, this.id});
  @override
  _MyMeetingDetailState createState() => _MyMeetingDetailState();
}

class _MyMeetingDetailState extends State<MyMeetingDetail> {
  MeetingInfoVo info;

  @override
  void initState() {
    super.initState();
    getInfo();
  }

  void getInfo() {
    MeetingApi().info(widget.id, success: (res) {
      setState(() {
        info = res;
        print(res.toJson());
      });
    }, error: (err) {
      print(err.code);
      showFailMessage(context);
    });
  }

  List<String> getUserNameList(List<UserVo> userVoList) {
    List<String> strList = [];
    userVoList.forEach((element) {
      strList.add(element.nickname);
    });
    return strList;
  }

  @override
  Widget build(BuildContext context) {
    return Card(
      margin: EdgeInsets.all(20),
      child: Container(
        width: 800,
        padding: EdgeInsets.all(20),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.center,
          children: [
            ItemTitle(info.name),
            ItemContext('状态：', info.statusName),
            ItemContext('类型：', info.typeName),
            ItemContext('地点：', info.place),
            ItemContext('主题：', info.topic),
            ItemContext('简要：',
                StrUtils.isBlank(info.description) ? "无" : info.description),
            ItemContext('发起人：', info.userName),
            ItemContext(
                '总结：', StrUtils.isBlank(info.summary) ? "无" : info.summary),
            ItemContext('开始时间：', info.beginTime),
            ItemContext('结束时间：', info.overTime),
            ItemList('参与人:', getUserNameList(info.participantList)),
          ],
        ),
      ),
    );
  }
}
